/*
============================================================================
 Name        : dd_audio_file.h
 Author      : Jian
 Version     :
 Copyright   : GPL
 Description : dd_audio_file.h - header file
============================================================================
*/

#ifndef DD_AUDIO_FILE_H
#define DD_AUDIO_FILE_H

/* INCLUDES */
#include "dd_define.h"

__DD_BEGIN_DECLS

typedef struct __dd_audio_file dd_audio_file ;
typedef struct __dd_audio_file_info dd_audio_file_info ;
typedef struct __dd_pcm_buffer dd_pcm_buffer ;

struct __dd_pcm_buffer {
    DD_UINT   len ;
    DD_UINT   second ;
    DD_BYTE   data[1] ;
} ;

struct __dd_audio_file {
    int  (*id)(dd_audio_file* file) ;
    int  (*info)(dd_audio_file* file, const dd_audio_file_info** fileInfo) ;
    int  (*decode)(dd_audio_file* file, dd_pcm_buffer* pcmBuffer) ;
    int  (*tell)(dd_audio_file* file) ;
    int  (*seek)(dd_audio_file* file, DD_UINT second) ;
    int  (*is_eof)(dd_audio_file* file) ;
    void (*destroy)(dd_audio_file* file) ;
} ;

#define dd_afile_id(f)        ((f)->id(f))
#define dd_afile_info(f, i)   ((f)->info(f, i))
#define dd_afile_decode(f, b) ((f)->decode(f, b))
#define dd_afile_tell(f)      ((f)->tell(f))
#define dd_afile_seek(f, s)   ((f)->seek(f, s))
#define dd_afile_is_eof(f)    ((f)->is_eof(f))
#define dd_afile_destroy(f)   ((f)->destroy(f))

struct __dd_audio_img {
    DD_UTF8*  mime ;
    DD_BYTE*  imgData ;
};

struct __dd_audio_file_info {

    int       id ;
    char      audioType[20 + 1] ;
    int       fileSize ;    
    int       bitrate ;         /* in kbs */
    int       samplerate ;
    int       duration ;        /* in second */       
    DD_UTF8*  title ;
    DD_UTF8*  artist ;
    DD_UTF8*  album ;
    struct __dd_audio_img* img ;
} ;

#define dd_destory_audio_info(i) do { __DD_ASSERT_DEFENSE(i, break); dd_destroy((i)->name); dd_destroy((i)->name); dd_destroy((i)->name); dd_destroy((i)->name); dd_destroy(i) ; } while (0) 

__DD_END_DECLS

#endif  /* DD_AUDIO_FILE_H */

/* End of File */
